<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cell {
    background: #fff;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  .weui-label{
    /*width: 130px;*/
    text-align: left;
  }

  .weui-select {
    height: auto;
    line-height: normal;
  }
  *{
    list-style:none;
  }
  /*body{*/

  /*}*/
  .weui-cell_select {
    padding: 10px 15px;
  }
  .weui-cells__title {
    text-align: left;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  input.time {
    border: none;
    font-size: 16px;
    padding-left: 10px;
  }
</style>
<template>
  <div v-if="itemdata.sellitems != undefined" class="oitem" :data-price="itemdata.price">
    <template v-for="(sell, index) in itemdata.sellitems">
      <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].guid'" :value="sell.guid" />
      <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].price'" :value="sell.price">
      <template v-if="settletype == 1">
        <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].unloadweight'" :value="sell.loadweight">
        <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].loadcount'" :value="sell.loadcount">
        <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].unloadcount'" :value="sell.unloadcount">
        <input type="hidden"  :name="'pitems[' + parseInt(packindex + index) + '].deductrate'" :value="sell.deductrate">
        <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].handselcount'" :value="sell.handselcount">
        <input type="hidden"  :name="'pitems[' + parseInt(packindex + index) + '].settlecount'" :value="sell.settlecount">
        <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].settleamount'" :value="sell.settleamount">
      </template>
      <template v-if="settletype == 2">
        <input v-if="deliverytype == 1" type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].unloadweight'" :value="sell.loadweight">
        <input type="hidden" :name="'pitems[' + parseInt(packindex + index) + '].handselweight'" :value="sell.handselweight">
      </template>
    </template>
    <div class="weui-cells__title">货品明细{{parseInt(itemindex) + 1}}
    </div>
    <div class="weui-cell fir">
      <div class="weui-cell__hd"><label class="weui-label">货品</label></div>
      <div class="weui-cell__bd">
        <input class="weui-input" type="text" readonly :value="itemdata.productname + '[' + itemdata.spname + ']'">
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">单价<span>({{payUnit}})</span></label></div>
      <div class="weui-cell__bd">
        <input class="weui-input" type="text" readonly :value="itemdata.price">
      </div>
    </div>
    <template v-if="settletype == 1">
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">发货件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :value="itemdata.loadcount">
        </div>
        <div class="weui-cell__hd"><label class="weui-label">到货件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :value="itemdata.unloadcount">
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd" v-if="itemdata.deductRate != ''"><label class="weui-label">赠送(%)</label></div>
        <div class="weui-cell__bd" v-if="itemdata.deductRate != ''">
          <input class="weui-input" type="text" readonly :value="itemdata.deductrate">
        </div>
        <div class="weui-cell__hd"><label class="weui-label">赠送件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :value="itemdata.loadhandsel">
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">结算件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input count" type="text" readonly :value="itemdata.settlecount">
        </div>
        <div class="weui-cell__hd"><label class="weui-label">结算金额</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :value="itemdata.settleamount">
        </div>
      </div>
    </template>
    <template v-if="settletype == 2">
      <div class="weui-cell" v-if="deliverytype == 1">
        <div class="weui-cell__hd"><label class="weui-label">重量</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input weight inlinput1" readonly type="number" :value="itemdata.loadweight">
          <input class="weui-input inlinput2" type="text" readonly value="吨">
        </div>
      </div>
      <div class="weui-cell" v-if="deliverytype == 2">
        <div class="weui-cell__hd"><label class="weui-label">重量</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input weight inlinput1" v-model="weight" type="number" placeholder="请输入重量">
          <input class="weui-input inlinput2" type="text" readonly value="吨">
        </div>
      </div>
<!--      <div class="weui-cell" v-if="itemdata.handselweight != ''">-->
<!--        <div class="weui-cell__hd"><label class="weui-label">赠送重量</label></div>-->
<!--        <div class="weui-cell__bd">-->
<!--          <input class="weui-input handselweight inlinput1" readonly type="number" :value="itemdata.handselweight">-->
<!--          <input class="weui-input inlinput2" type="text" readonly value="吨">-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="weui-cell">-->
<!--        <div class="weui-cell__hd"><label class="weui-label">扣杂率(%)</label></div>-->
<!--        <div class="weui-cell__bd">-->
<!--          <input class="weui-input discount" v-if="deducttype == 4" readonly v-model="discount" type="number">-->
<!--          <input class="weui-input discount" v-if="deducttype != 4" v-model="discount" type="number" placeholder="请输入扣杂率">-->
<!--        </div>-->
<!--      </div>-->
    </template>
  </div>
  <div v-else class="oitem" :data-price="itemdata.price">
    <input type="hidden" :name="'pitems[' + parseInt(packindex) + '].guid'" :value="itemdata.guid" />
    <div class="weui-cells__title">货品明细{{parseInt(itemindex) + 1}}
    </div>
    <div class="weui-cell fir">
      <div class="weui-cell__hd"><label class="weui-label">货品</label></div>
      <div class="weui-cell__bd">
        <input class="weui-input" type="text" readonly :value="itemdata.productname + '[' + itemdata.spname + ']'">
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">单价<span>({{payUnit}})</span></label></div>
      <div class="weui-cell__bd">
        <input class="weui-input" type="text" readonly :name="'pitems[' + packindex + '].price'" :value="itemdata.price">
      </div>
    </div>
    <template v-if="settletype == 1">
      <input class="weui-input" type="hidden" :name="'pitems[' + packindex + '].unloadweight'" :value="itemdata.loadweight">
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">发货件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :name="'pitems[' + packindex + '].loadcount'" :value="itemdata.loadcount">
        </div>
        <div class="weui-cell__hd"><label class="weui-label">到货件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :name="'pitems[' + packindex + '].unloadcount'" :value="itemdata.unloadcount">
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd" v-if="itemdata.deductRate != ''"><label class="weui-label">赠送(%)</label></div>
        <div class="weui-cell__bd" v-if="itemdata.deductRate != ''">
          <input class="weui-input" type="text" readonly :name="'pitems[' + packindex + '].deductrate'" :value="itemdata.deductrate">
        </div>
        <div class="weui-cell__hd"><label class="weui-label">赠送件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :name="'pitems[' + packindex + '].loadhandsel'" :value="itemdata.loadhandsel">
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">结算件数</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input count" type="text" readonly :name="'pitems[' + packindex + '].settlecount'" :value="itemdata.settlecount">
        </div>
        <div class="weui-cell__hd"><label class="weui-label">结算金额</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" readonly :name="'pitems[' + packindex + '].settleamount'" :value="itemdata.settleamount">
        </div>
      </div>
    </template>
    <template v-if="settletype == 2">
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">出库数量</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input inlinput1" :name="'pitems[' + packindex + '].unloadweight'" readonly type="number" :value="itemdata.loadweight">
          <input class="weui-input inlinput2" readonly type="text" :value="itemdata.unit">
        </div>
      </div>
<!--      <div class="weui-cell" v-if="deliverytype == 1">-->
<!--        <div class="weui-cell__hd"><label class="weui-label">结算数量</label></div>-->
<!--        <div class="weui-cell__bd">-->
<!--          <input class="weui-input weight inlinput1" readonly type="number" :name="'pitems[' + packindex + '].unloadweight'" :value="itemdata.loadweight">-->
<!--          <input class="weui-input inlinput2" readonly type="text" :value="itemdata.unit">-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="weui-cell" v-if="deliverytype == 2">-->
<!--        <div class="weui-cell__hd"><label class="weui-label">结算数量</label></div>-->
<!--        <div class="weui-cell__bd">-->
<!--          <input class="weui-input weight inlinput1" v-model="weight" type="number" :name="'pitems[' + packindex + '].unloadweight'" placeholder="请输入数量">-->
<!--          <input class="weui-input inlinput2" type="text" :value="itemdata.unit">-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="weui-cell" v-if="itemdata.handselweight != ''">-->
<!--        <div class="weui-cell__hd"><label class="weui-label">赠送数量</label></div>-->
<!--        <div class="weui-cell__bd">-->
<!--          <input class="weui-input handselweight inlinput1" readonly type="number" :name="'pitems[' + packindex + '].handselweight'" :value="itemdata.handselweight">-->
<!--          <input class="weui-input inlinput2" readonly type="text" :value="itemdata.unit">-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="weui-cell">-->
<!--        <div class="weui-cell__hd"><label class="weui-label">扣杂率(%)</label></div>-->
<!--        <div class="weui-cell__bd">-->
<!--          <input class="weui-input discount" v-if="deducttype == 4" readonly v-model="discount" type="number" :name="'pitems[' + packindex + '].deductrate'">-->
<!--          <input class="weui-input discount" v-if="deducttype != 4" v-model="discount" type="number" :name="'pitems[' + packindex + '].deductrate'" placeholder="请输入扣杂率">-->
<!--        </div>-->
<!--      </div>-->
    </template>
  </div>
</template>

<script>
export default {
  name: 'SellFinalSureItem',
  data () {
    return {
      weight: '',
      discount: '',
      deducttype: '',
      deliverytype: 2
    }
  },
  props: [
    'itemindex',
    'itemdata',
    'settletype',
    'concessiontype',
    // 'deliverytype',
    'quitSRType',
    'packindex'
  ],
  computed: {
    payUnit: function () {
      return this.settletype == 1 ? '元/件' : '元/吨';
    }
  },
  mounted() {
    if (this.deliverytype == 1 && this.settletype == 2 ) {
      this.computeFinal();
    }
    if (this.settletype == 2) {
      this.getDiscountType();
    }
    //this.weight = this.itemdata.loadweight;
  },
  watch: {
    // 'itemdata': function (val) {
    //   if (val.deliverytype == 1) {
    //     this.weight = val.loadweight;
    //   }
    // },
    'weight': function (val) {
      this.computeFinal();
    },
    'discount': function (val) {
      this.computeFinal();
    },
  },
  methods: {
    getDiscountType: function() {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Sellform!getDiscountType.action',
        params: {type: this.quitSRType}
      }).then(response => {
        let data = response.data;
        if (data.code == 1) {
          this.deducttype = data.msg.deducttype;
        } else if (data.code == 0) {
          this.toastText(data.msg);
        } else {
          this.toastText('获取系统参数失败');
        }
      });
    },
    computeFinal: function() {
      this.$emit('getFinal');
    },
  }
}
</script>
